#version 120

//this is insipred by the sources mentioned in openglframework.c
varying vec3 N;
varying vec4 pos;

//uniform vec4 kBlue ;
//uniform vec4 kYellow;
//uniform vec4 alpha;
//uniform vec4 beta;

void main (void)
{
	vec4 kBlue = vec4(0.0, 0.0, 0.55, 1.0);
	vec4 kYellow = vec4(0.3, 0.3, 0.0, 1.0);
	vec4 alpha = vec4(0.25, 0.25, 0.25, 1.0);
	vec4 beta = vec4(0.5, 0.5, 0.5, 1.0);

	vec4 kCool = kBlue + alpha * gl_LightSource[0].diffuse * gl_FrontMaterial.diffuse;
	vec4 kWarm = kYellow + beta * gl_LightSource[0].diffuse * gl_FrontMaterial.diffuse; 
	
	vec4 lpos = gl_LightSource[0].position;
	vec3 L = -normalize(pos.xyz - lpos.xyz); 
	float dot_N_L = dot(N,L);	
	
	vec4 gooch;
	
	//if (dot_N_L >= 0.0) {
	gooch = kCool * (1-dot_N_L)/2 + kWarm * (1+dot_N_L)/2;
	//}	
	
	// Add specular components
	vec3 R = -reflect(L, N);
	R = normalize(R);
	vec3 V = -pos.xyz;
	V = normalize(V);
	vec4 specular;
	
    specular = gl_LightSource[0].specular * gl_FrontMaterial.specular * pow(max(0.0,dot(R, V)), gl_FrontMaterial.shininess);
    
    gl_FragColor = specular + gooch;
}
